<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class JR_Router extends CI_Router
{
	public function __construct()
	{
		parent::__construct();
	}

	function _validate_request($segments)
	{
		// print_r($segments);exit;
		if(sizeof($segments)>=2 && $segments[1]=="module")
		{
			return $this->_validate_module_request($segments);
		}
		else
		{
			return parent::_validate_request($segments);
		}
	}

	// --------------------------------------------------------------------

	/**
	 * Module 的访问直接路由到特殊的 Module_proxy 控制器
	 *
	 * @access	private
	 * @param	array
	 * @return	array
	 */
	function _validate_module_request($segments)
	{
		// $segments = array_slice($segments, 1);
		// print_r($segments);exit; 
		$this->set_directory('../third_party');
		$this->set_class('module_proxy');
		$this->set_method('index'); 
		/*
		$CI = & get_instance();
		$controller = isset($segments[3])?$segments[3]:$CI->defaultcontroller;
		echo  $segments[1]."s/".$segments[2]."/controllers/".$segments[0]."/".$controller;exit; */
		return $segments;
	}

	function _set_request($segments = array())
	{
		if(sizeof($segments)>=2 && $segments[1]=="module")
		{
			$segments = array_slice($segments,2) ;    
			$segments = $this->_validate_module_request($segments); 
			$this->uri->rsegments = $segments; 
		}
		else if(sizeof($segments)>=2 && $segments[1]=="script")
		{
			$segments = array_slice($segments,1) ;
			parent::_set_request($segments);
		}
		else
		{
			parent::_set_request($segments);
		}
	}

	// --------------------------------------------------------------------

	/**
	 *  Set the directory name
	 *
	 * @access	public
	 * @param	string
	 * @return	void
	 */
	function set_directory($dir)
	{
		$this->directory = $dir.'/';
	}

}

/* End of file MY_Router.php */
/* Location: ./application/core/MY_Router.php */
